//
//  MBProgressHUD+HM.m
//  MBProgressHudTest
//
//  Created by itcastteacher on 16/11/6.
//  Copyright © 2016年 itcastteacher. All rights reserved.
//

#import "MBProgressHUD+HM.h"

#define kWindow ([UIApplication sharedApplication].keyWindow)

@implementation MBProgressHUD (HM)


+ (void)showErrorMessage:(NSString *)message {
    [self showMessage:message withSuccess:NO];
}

+(void)showSuccessMessage:(NSString *)message {
    
    [self showMessage:message withSuccess:YES];
}


+ (void)showMessage:(NSString *)message withSuccess:(BOOL)success {
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:kWindow animated:YES];
    
    // 增加背景的挡板
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    // colorWithWhite: 表示颜色中白色所占的比例
    hud.backgroundView.color = [UIColor colorWithWhite:0 alpha:0.1];
    
    NSString *imageString = success ? @"MBProgressHUD.bundle/Checkmark" : @"MBProgressHUD.bundle/error";
    
    // 自定义的view
    UIImage *image = [UIImage imageNamed:imageString];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
    hud.customView = imageView;
    hud.mode = MBProgressHUDModeCustomView;
    
    hud.label.text = message;
    
    // 在1.5秒之后, 隐藏起来
    [hud hideAnimated:YES afterDelay:1.5];
}

+ (void)showLoading {
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:kWindow animated:YES];
    
    hud.label.text = @"Loading...";
    
    // 增加背景的挡板
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    // colorWithWhite: 表示颜色中白色所占的比例
    hud.backgroundView.color = [UIColor colorWithWhite:0 alpha:0.1];
}

+ (void)removeAllHudForWindow {
    
    [MBProgressHUD hideHUDForView:kWindow animated:YES];
}

@end
